﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

namespace WcfService_Restful.DAO
{
    public class QuanHuyen_DAO : DataProvider
    {
        public QuanHuyen_DAO()
        {
            Connect();
        }

        public object ConvertDataTableToArray(DataTable dt, int i)
        {
            DTO.QuanHuyen_DTO data = new DTO.QuanHuyen_DTO();
            data.MaQuanHuyen = Convert.ToInt32(dt.Rows[i]["MaQuanHuyen"].ToString());
            data.TenQuanHuyen = dt.Rows[i]["TenQuanHuyen"].ToString();               
            return (object)data;
        }

        public DTO.QuanHuyen_DTO[] GetData()
        {
            try
            {
                String sql = "Select * From QuanHuyen Order By TenQuanHuyen Asc";
                DataTable dt = ExecuteQuery(sql);
                DTO.QuanHuyen_DTO[] ds = new DTO.QuanHuyen_DTO[dt.Rows.Count];
                for (int i = 0; i < dt.Rows.Count; i++)
                    ds[i] = (DTO.QuanHuyen_DTO)ConvertDataTableToArray(dt, i);
                Disconnect();
                return ds;
            }
            catch
            {
                Disconnect();
                return null;
            }
        }
    }
}